<?php
session_start();
date_default_timezone_set("Asia/Chongqing");
include("../../config/connect.php");
include("../../public/common.php");

$opt = trim(CheckUrlParamNoDie("opt"));
$showtype = trim(CheckUrlParamNoDie("showtype"));
$id = CheckUrlParamNoDie("id");

if(isset($_POST["Site_Submit"]))
{
	$sitename = trim(isset($_POST['Site_Name']) ? $_POST['Site_Name'] : "");
	$siteurl = trim(isset($_POST['Site_Url']) ? $_POST['Site_Url'] : "");
	$sitelogo = trim(isset($_POST['Site_Logo']) ? $_POST['Site_Logo'] : "");
	$sitetag = trim(isset($_POST['Site_Tag']) ? $_POST['Site_Tag'] : "");
	$sitedes = trim(isset($_POST['Site_Descript']) ? $_POST['Site_Descript'] : "");

	$sql2 = "update union_zz set name='$sitename', url='$siteurl', pic_url='$sitelogo', type='$sitetag', descript='$sitedes' where id=$id";
	mysql_query($sql2);
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-2);</script>";
}
if ($opt == "del" && $id != "")
{
	mysql_query("delete from union_zz where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}else if ($opt == "checkok" && $id != "")
{
	mysql_query("update union_zz set state=1 where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}else if ($opt == "checno" && $id != "")
{
	mysql_query("update union_zz set state=0 where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>设置</title>
<LINK rel=stylesheet type=text/css href="../css/style.css">
<script language="javascript" src="../js/jquery.min.js"></script>
<style type="text/css">
body { font-size:14px;}
table,tr,th,td { margin:0; padding:0; color:#666;}
table { background:#09F;}
th { background:#BEF;}
th,td { padding:10px;}
tr { background:#fff;}
</style>
</head>
<body>
<div style="padding:10px;"><a href="union.php" target="_blank">点击打开站长联盟</a>&nbsp;&nbsp;
	<?php 
 		if($showtype == 'checkno'){
			echo '&nbsp;&nbsp;<a href="adminuntion.php">未审核</a>&nbsp;&nbsp;<b>已审核</b>';
		}else{
			echo '&nbsp;&nbsp;<b>未审核</b>&nbsp;&nbsp;<a href="?showtype=checkno">已审核</a>';
		}
	?>
	</div>
<table cellpadding="10" cellspacing="1" border="0" width="100%" style="color:red">
	<tr>
    	<th>序号</th>
    	<th>网站名称</th>
        <th>网站URL</th>
        <th>网站LOGO</th>
        <th>网站类型</th>
        <th>网站简介</th>
        <th>操作</th>
    </tr>
    <?php
    $sql = "select * from union_zz";
	if(!isset($showtype) || $showtype == '')
		$sql .= " where state='0'";
	else if($showtype == 'checkno')
		$sql .= " where state='1'";
		
	$result = mysql_query($sql);
	$i = 0;
	while( $result && $row = mysql_fetch_assoc($result))
	{
	?>
    <tr>
    	<td><?php echo $row["id"]; ?></td>
    	<td><?php echo $row["name"]; ?></td>
        <td><a href="<?php echo $row["url"]; ?>" target="_blank"><?php echo $row["url"]; ?></a></td>
        <td><img src="<?php echo $row["pic_url"]; ?>" alt="<?php echo $row["name"]; ?>" /></td>
        <td><?php echo $row["type"]; ?></td>
        <td><?php echo $row["descript"]; ?></td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?opt=edit&id=<?php echo $row["id"]; ?>">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <?php
			if($row["state"] == 0){
				echo "<a href='?opt=checkok&id=".$row["id"]."'>审核通过</a>&nbsp;&nbsp;&nbsp;&nbsp;";
			}else if($row["state"] == 1){
				echo "<a href='?opt=checno&id=".$row["id"]."'>不通过</a>&nbsp;&nbsp;&nbsp;&nbsp;";
			}
		 ?>
         <a href="javascript:if(confirm('确实要删除吗?'))location='?opt=del&id=<?php echo $row["id"]; ?>'">删除</a>
    </tr>
    <?php } ?>
</table>
<?php 
if($opt == "edit" && $id != "")
{ 
	//$siid = "";
	$siname = "";
	$siurl = "";
	$silogo = "";
	$sitag = "";
	$sides = "";
	
	if( $id != "" )
	{
		$esql = "select * from union_zz where id=$id limit 1";
		$eresult = mysql_query( $esql );
		if( $eresult && $row2 = mysql_fetch_assoc( $eresult ) )
		{
			//$siid = 
			$siname = $row2["name"];
			$siurl = $row2["url"];
			$silogo = $row2["pic_url"];
			$sitag = $row2["type"];
			$sides = $row2["descript"];
		}
	}
?>
<div style="display:block;" class="Unbound">
    <div class="unss">
        <div class="sel"><h2><span class="Close"><a href="adminuntion.php">关闭</a></span>网站提交</h2></div>
        <div class="ted">
            <form onsubmit="return sunbmintSS()" method="post" action="adminuntion.php?id=<?php echo $id; ?>">
                <div class="ted_tj"><span>网站名称：</span><input type="text" value="<?php echo $siname; ?>" name="Site_Name" id="Site_Name" maxlength="100" style="width:160px;" class="tedinp"></div>
                <div class="ted_tj"><span>网站地址：</span><input type="text" value="<?php echo $siurl; ?>" name="Site_Url" id="Site_Url" maxlength="100" style="width:360px;" class="tedinp"></div>
                <div class="ted_tj"><span>网站LOGO：</span><input type="text" value="<?php echo $silogo; ?>" name="Site_Logo" id="Site_Logo" maxlength="100" style="width:360px;" class="tedinp"></div>
                <div class="ted_tj"><span>网站类型：</span><select size="1" id="Site_Tag" name="Site_Tag" class="tedinp">
                  <option value="<?php echo $sitag; ?>"><?php echo $sitag; ?></option>
                  <option value="娱乐休闲">娱乐休闲</option>
                  <option value="商业经济">商业经济</option>
                  <option value="电脑网络">电脑网络</option>
                  <option value="卫生健康">卫生健康</option>
                  <option value="文学艺术">文学艺术</option>
                  <option value="教育培训">教育培训</option>
                  <option value="体育健身">体育健身</option>
                  <option value="旅游交通">旅游交通</option>
                  <option value="地方热线">地方热线</option>
                  <option value="生活服务">生活服务</option>
                  <option value="参考资料">参考资料</option>
                  <option value="新闻媒体">新闻媒体</option>
                  <option value="行业网站">行业网站</option>
                  <option value="其它类别">其它类别</option>
                </select>
                </div>
                <div class="ted_tj"><span>网站简介：</span><div><textarea name="Site_Descript" id="Site_Descript" rows="3" cols="90"><?php echo $sides; ?></textarea></div></div>
                <p class="sz_btn"><input type="submit" value="提 交" name="Site_Submit" id="Site_Submit"></p>
                <span><!-----奇怪的360 去掉设置就没有了------></span>
            </form>
        </div>
    </div>
</div>
<?php } ?>
</body>
</html>
<script type="text/javascript">
function sunbmintSS()
{
	var sitename = document.getElementById("Site_Name").value;
	var siteurl = document.getElementById("Site_Url").value;
	var sitelogo = document.getElementById("Site_Logo").value;
	var sitetag = document.getElementById("Site_Tag").value;
	
	if(sitename == "" || siteurl == "" || sitelogo == "" || sitetag == "请选择")
	{
		alert("请检查一下是否有什么没有输入，不能为空");
		//document.getElementById("Site_Name").focus();
		return false;
	}
	
	return true;
}
</script>
